﻿using System.Text;

namespace  DTU_Test;

/// <summary>
/// 设置信息，来自于配置工具
/// </summary>
public class DTUSetting
{
    /// <summary>
    /// 设备名称或设备ID，如："DTU_123456"，”2025051800000001“
    /// </summary>
    public string? DeviceName { get; set; }

    /// <summary>
    /// 透出服务器IP地址，默认115.29.149.229
    /// </summary>
    public string? ServerIP { get; set; }

    /// <summary>
    /// 透传服务器端口号，默认5555
    /// </summary>
    public int ServerPort { get; set; } //服务器端口号

    /// <summary>
    /// 心跳包间隔时间，单位秒，默认30秒
    /// </summary>
    public int HeartBeatInterval { get; set; } //心跳包间隔时间

    /// <summary>
    /// APN名称
    /// </summary>
    public string APNName { get; set; }

    /// <summary>
    /// //APN用户名
    /// </summary>
    public string UserName { get; set; }

    /// <summary>
    /// //APN密码
    /// </summary>
    public string Password { get; set; }

    /// <summary>
    /// 加密方式
    /// </summary>
    public int Encryption { get; set; }

    /// <summary>
    /// 串口波特率，默认9600
    /// </summary>
    public int BaudRate { get; set; } //波特率

    /// <summary>
    /// 串口数据位，默认8位
    /// </summary>
    public int DataBits { get; set; } //数据位

    /// <summary>
    /// 串口停止位，默认1位
    /// </summary>
    public int StopBits { get; set; } //停止位

    /// <summary>
    /// 串口校验位，默认无校验
    /// </summary>
    public int Parity { get; set; } //校验位

    /// <summary>
    /// 转换成字节数组
    /// </summary>
    /// <returns></returns>
    public byte[] ToBytes()
    {
        string tem = this.ToJson();
        return ASCIIEncoding.Default.GetBytes(tem);
    }
}